package com.sheng.leetcode.year2023.month04.day25;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author liusheng
 * @date 2023/04/25
 * <p>
 * 2418. 按身高排序<p>
 * <p>
 * 给你一个字符串数组 names ，和一个由 互不相同 的正整数组成的数组 heights 。两个数组的长度均为 n 。<p>
 * 对于每个下标 i，names[i] 和 heights[i] 表示第 i 个人的名字和身高。<p>
 * 请按身高 降序 顺序返回对应的名字数组 names 。<p>
 * <p>
 * 示例 1：<p>
 * 输入：names = ["Mary","John","Emma"], heights = [180,165,170]<p>
 * 输出：["Mary","Emma","John"]<p>
 * 解释：Mary 最高，接着是 Emma 和 John 。<p>
 * <p>
 * 示例 2：<p>
 * 输入：names = ["Alice","Bob","Bob"], heights = [155,185,150]<p>
 * 输出：["Bob","Alice","Bob"]<p>
 * 解释：第一个 Bob 最高，然后是 Alice 和第二个 Bob 。<p>
 * <p>
 * 提示：<p>
 * n == names.length == heights.length<p>
 * 1 <= n <= 10^3<p>
 * 1 <= names[i].length <= 20<p>
 * 1 <= heights[i] <= 10^5<p>
 * names[i] 由大小写英文字母组成<p>
 * heights 中的所有值互不相同<p>
 * <p>
 * 来源：力扣（LeetCode）<p>
 * 链接：<a href="https://leetcode.cn/problems/sort-the-people">2418. 按身高排序</a><p>
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。<p>
 */
public class LeetCode2418 {

    @Test
    public void test01() {
//        String[] names = {"Mary", "John", "Emma"};
//        int[] heights = {180, 165, 170};
        String[] names = {"Alice", "Bob", "Bob"};
        int[] heights = {155, 185, 150};
        System.out.println(Arrays.toString(new Solution().sortPeople(names, heights)));
    }
}

class Solution {
    public String[] sortPeople(String[] names, int[] heights) {
        int length = names.length;
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                if (heights[i] < heights[j]) {
                    int temp = heights[i];
                    heights[i] = heights[j];
                    heights[j] = temp;
                    String str = names[i];
                    names[i] = names[j];
                    names[j] = str;
                }
            }
        }
        return names;
    }
}
